package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.payconfig.EntitySchoolPhoneInfo;
import com.ocom.common.vo.payconfig.schoolphone.SchoolPhoneInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface IDaoSchoolPhone extends BaseMapper<EntitySchoolPhoneInfo> {

    @Select({"<script>",
            "SELECT p.com_id, p.dept_id, d.dept_name, p.p_id, p.p_code, p.p_name, p.p_sex, ",
            "s.phone_info, s.use_info, s.customer_info, s.qr_code_url, s.remark, s.update_user, s.update_time ",
            "FROM personnel_info p ",
            "LEFT JOIN school_phone_info s ON p.com_id = s.com_id AND p.p_id = s.p_id ",
            "LEFT JOIN dept_info d ON p.com_id = d.com_id AND p.dept_id = d.dept_id ",
            "WHERE p.com_id = #{schoolPhoneInfoVo.comId} AND p.status = 0 ",
            "<if test='schoolPhoneInfoVo.pCode != null'>AND p.p_code = #{schoolPhoneInfoVo.pCode}</if> ",
            "<if test='schoolPhoneInfoVo.pName != null'>AND p.p_name LIKE concat('%', #{schoolPhoneInfoVo.pName}, '%')</if> ",
            "<if test='schoolPhoneInfoVo.pId != null'>AND p.p_id = #{schoolPhoneInfoVo.pId}</if> ",
            "<if test='schoolPhoneInfoVo.deptId != null'>AND p.dept_id = #{schoolPhoneInfoVo.deptId}</if> ",
            "<if test='schoolPhoneInfoVo.phoneInfo != null'>AND s.phone_info LIKE concat('%', #{schoolPhoneInfoVo.phoneInfo}, '%')</if> ",
            "ORDER BY s.update_time DESC",
            "</script>"})
    List<SchoolPhoneInfoVo> getSchoolPhoneList( @Param("schoolPhoneInfoVo") SchoolPhoneInfoVo schoolPhoneInfoVo);

}

